package com.pr.makfilm.core.cmp.feedback;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.feedback.IFeedbackMessageFilter;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

/**
 * Created with IntelliJ IDEA.
 * User: Pawel
 * Date: 24.09.13
 * Time: 21:27
 * To change this template use File | Settings | File Templates.
 */
public class FormFeedbackPanel extends FeedbackPanel
{
   private static final String CONTAINER_CLASS = "has-";

   private WebMarkupContainer container;

   public FormFeedbackPanel(String id, IFeedbackMessageFilter filter, WebMarkupContainer container)
   {
      super(id, filter);
      this.container = container;
   }

   @Override
   protected void onConfigure()
   {
      if (!anyMessage())
      {
         container.add(AttributeModifier.replace("class", CONTAINER_CLASS));
      }
   }

   @Override
   protected String getCSSClass(final FeedbackMessage message)
   {
      String messageLevel = message.getLevelAsString();
      container.add(AttributeModifier.replace("class", CONTAINER_CLASS + messageLevel.toLowerCase()));
      return super.getCSSClass(message);
   }
}
